#include "rsutransgetobusysinfo.h"

void RsuTransGetObuSysInfo::start()
{
    m_nCurrentStep=TS_INIT_OBU;
    if (m_pRsuCtrl->checkRsuStatus())
    {
        // 在特定时间间隔检测天线状态，此时等待心跳信号返回，不搜寻OBU
        m_pTransTimer->start(200);
    }
    else
    {
        m_pRsuCtrl->detectObu();
        m_pTransTimer->start(150);
    }
}

void RsuTransGetObuSysInfo::processRsuFrame(quint8 nFrameIndex, quint8 nFrameType, const QByteArray &frame)
{
    Q_UNUSED(nFrameIndex);

    if (0xE1==nFrameType)
    {
        if (m_nCurrentStep==RsuTransGetObuSysInfo::TS_INIT_OBU)
        {
            if (m_pRsuCtrl->processObuInitFrame(frame))
            {
                // NOTE: 等待业务层判断是否继续交易
                m_nCurrentStep=RsuTransGetObuSysInfo::TS_WAIT_INSTRUCTION;
                m_pTransTimer->start(200);
            }
            else
            {
                this->start();
            }
        }
        else
        {
            this->start();
        }
    }
    else if (0xE0==nFrameType)
    {
        m_pRsuCtrl->processRsuInitFrame(frame);
        start();
    }
    else if (0xE7==nFrameType)
    {
        m_pRsuCtrl->processRsuInfoFrame(frame);
        start();
    }
    else
    {
        this->start();
    }
}

